/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * formData.java
 *
 * Created on 24 Apr 12, 10:36:17
 */
package com.DaftarPegawai;

import com.DataPegawai.*;
import com.Main.MainForm;
import com.PiketPegawai.PIketPegawaiForm;
import com.entities.Pegawai;
import com.entities.pegawaiTableModel;
import com.strukturOrganisasi.StrukturOrganisasiiForm;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Ignacio
 */
public class daftarPegawaiForm extends javax.swing.JFrame {

    /** Creates new form formData */
    public daftarPegawaiForm() {
        initComponents();
        this.setSize(1015, 640);
        try {
            List<Pegawai> pegawaiList;
            pegawaiList = Pegawai.getKoneksiKontrol().ambilPegawai();
            pegawaiTableModel model = new pegawaiTableModel(pegawaiList);
            pegawaiTabel.setModel(model);
            daftarPegawaiControl.setForm(this);
            //        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(daftarPegawaiForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(daftarPegawaiForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelAwal = new javax.swing.JPanel();
        headerPanel = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        mainPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        pegawaiTabel = new javax.swing.JTable();
        tambahButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        Edit = new javax.swing.JButton();
        MenuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        strukturMenu = new javax.swing.JMenuItem();
        piketMenu = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Sistem Kepegawaian Puskesmas Jebed - Daftar Pegawai");
        setResizable(false);

        headerPanel.setBackground(new java.awt.Color(153, 255, 204));

        jLabel10.setBackground(new java.awt.Color(51, 255, 204));
        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/imagePKM.png"))); // NOI18N

        javax.swing.GroupLayout headerPanelLayout = new javax.swing.GroupLayout(headerPanel);
        headerPanel.setLayout(headerPanelLayout);
        headerPanelLayout.setHorizontalGroup(
            headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(headerPanelLayout.createSequentialGroup()
                .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 989, Short.MAX_VALUE)
                .addContainerGap())
        );
        headerPanelLayout.setVerticalGroup(
            headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(headerPanelLayout.createSequentialGroup()
                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        mainPanel.setBackground(new java.awt.Color(255, 255, 255));

        pegawaiTabel.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "NIP", "Nama", "Tempat Lahir", "Tanggal Lahir", "Jenis Kelamin", "Pendidikan", "Status Pegawai", "Golongan", "Gaji Pokok"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Long.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(pegawaiTabel);

        tambahButton.setText("Tambah");
        tambahButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        tambahButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tambahButtonActionPerformed(evt);
            }
        });

        deleteButton.setText("Hapus");
        deleteButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        Edit.setText("Edit");
        Edit.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        Edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 956, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(tambahButton)
                        .addGap(81, 81, 81)
                        .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(72, 72, 72)
                        .addComponent(Edit, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tambahButton)
                    .addComponent(deleteButton)
                    .addComponent(Edit))
                .addContainerGap(183, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout panelAwalLayout = new javax.swing.GroupLayout(panelAwal);
        panelAwal.setLayout(panelAwalLayout);
        panelAwalLayout.setHorizontalGroup(
            panelAwalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAwalLayout.createSequentialGroup()
                .addGroup(panelAwalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(headerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        panelAwalLayout.setVerticalGroup(
            panelAwalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAwalLayout.createSequentialGroup()
                .addComponent(headerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        fileMenu.setText("File");

        strukturMenu.setText("Struktur Organisasi");
        strukturMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                strukturMenuActionPerformed(evt);
            }
        });
        fileMenu.add(strukturMenu);

        piketMenu.setText("Piket Pegawai");
        piketMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                piketMenuActionPerformed(evt);
            }
        });
        fileMenu.add(piketMenu);

        jMenuItem4.setText("Menu Awal");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem4);

        MenuBar.add(fileMenu);

        helpMenu.setText("Help");
        MenuBar.add(helpMenu);

        setJMenuBar(MenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelAwal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelAwal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1015)/2, (screenSize.height-731)/2, 1015, 731);
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        // TODO add your handling code here:
        MainForm call = new MainForm();
        call.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void strukturMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_strukturMenuActionPerformed
        // TODO add your handling code here:
        StrukturOrganisasiiForm call = new StrukturOrganisasiiForm();
        call.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_strukturMenuActionPerformed

    private void piketMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_piketMenuActionPerformed
        // TODO add your handling code here:
        // TODO add your handling code here:
        PIketPegawaiForm call = new PIketPegawaiForm();
        call.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_piketMenuActionPerformed

    private void tambahButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tambahButtonActionPerformed
        // TODO add your handling code here:
        if(tambahPegawaiControl.getFrame()==null){
        tambahPegawaiForm test = new tambahPegawaiForm(0);
        test.setVisible(true);
        }
        else 
            tambahPegawaiControl.getFrame().show();
        this.dispose();
    }//GEN-LAST:event_tambahButtonActionPerformed

    private void EditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditActionPerformed
        // TODO add your handling code here:
        if(tambahPegawaiControl.getFrame()==null){
        Pegawai.setPegs(daftarPegawaiControl.selectPegawaiAction(pegawaiTabel));
        tambahPegawaiForm test = new tambahPegawaiForm(1);
        test.setVisible(true);
        }
        else 
            tambahPegawaiControl.getFrame().show();
        this.dispose();
    }//GEN-LAST:event_EditActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        try {
            // TODO add your handling code here:
            daftarPegawaiControl.hapusPegawaiAction(pegawaiTabel);
            JOptionPane.showMessageDialog(null, "Pegawai "+
                    pegawaiTabel.getValueAt(pegawaiTabel.getSelectedRow(), 0)+" berhasil dihapus.");
            List<Pegawai> pegawaiList;
            pegawaiList = Pegawai.getKoneksiKontrol().ambilPegawai();
            pegawaiTableModel model = new pegawaiTableModel(pegawaiList);
            pegawaiTabel.setModel(model);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(daftarPegawaiForm.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, "Gagal menghapus pegawai!","Warning",2);
        } catch (SQLException ex) {
            Logger.getLogger(daftarPegawaiForm.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, "Gagal menghapus pegawai!","Warning",2);
        }
    }//GEN-LAST:event_deleteButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Edit;
    private javax.swing.JMenuBar MenuBar;
    private javax.swing.JButton deleteButton;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JPanel headerPanel;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JPanel panelAwal;
    private javax.swing.JTable pegawaiTabel;
    private javax.swing.JMenuItem piketMenu;
    private javax.swing.JMenuItem strukturMenu;
    private javax.swing.JButton tambahButton;
    // End of variables declaration//GEN-END:variables
}
